/**
 *  Copyright [2021] Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. 
 */
#include "aicl.h"
#include "acl/acl.h"
#include "acl/acl_op.h"
#include "acl/acl_op_compiler.h"
#include "ge/ge_api.h"
#include "ge/ge_ir_build.h"
#include "graph/ge_error_codes.h"
using namespace std;

aiclRet errcod_trans(aclError ret) {
    switch (ret)
    {
        case ACL_SUCCESS:
            return AICL_RET_SUCCESS;
        case ge::GRAPH_FAILED:
            return AICL_RET_ERROR;
        case ACL_ERROR_RT_NO_DEVICE:
            return AICL_RET_INVALID_DEVICE;
        case ACL_ERROR_RT_INVALID_DEVICEID:
            return AICL_RET_INVALID_DEVICE_ID;
        case ACL_ERROR_REPEAT_INITIALIZE:
            return AICL_RET_REPEAT_INITIALIZE;
        case ACL_ERROR_INVALID_FILE:
            return AICL_RET_INVALID_FILE;
        case ACL_ERROR_WRITE_FILE:
            return AICL_RET_WRITE_FILE_FAILURE;
        case ACL_ERROR_INVALID_FILE_SIZE:
            return AICL_RET_INVALID_FILE_SIZE;
        case ACL_ERROR_PARSE_FILE:
            return AICL_RET_PARSE_FILE_FAILURE;
        case ACL_ERROR_FILE_MISSING_ATTR:
        case ACL_ERROR_FILE_ATTR_INVALID:
            return AICL_RET_INVALID_FILE_ATTR;
        case ACL_ERROR_INVALID_MODEL_ID:
            return AICL_RET_INVALID_MODEL_ID;
        case ACL_ERROR_DESERIALIZE_MODEL:
            return AICL_RET_DESERIALIZE_MODEL_FAILURE;
        case ACL_ERROR_PARSE_MODEL:
            return AICL_RET_PARSE_MODEL_FAILURE;
        case ACL_ERROR_READ_MODEL_FAILURE:
            return AICL_RET_READ_MODEL_FAILURE;
        case ACL_ERROR_MODEL_SIZE_INVALID:
            return AICL_RET_INVALID_MODEL_SIZE;
        case ACL_ERROR_MODEL_MISSING_ATTR:
            return AICL_RET_INVALID_MODEL_ATTR;
        case ACL_ERROR_MODEL_INPUT_NOT_MATCH:
            return AICL_RET_INVALID_MODEL_INPUT;
        case ACL_ERROR_MODEL_OUTPUT_NOT_MATCH:
            return AICL_RET_INVALID_MODEL_OUTPUT;
        case ACL_ERROR_MODEL_NOT_DYNAMIC:
            return AICL_RET_INVALID_DYNAMIC_MODEL;
        case ACL_ERROR_OP_TYPE_NOT_MATCH:
            return AICL_RET_INVALID_OP_TYPE;
        case ACL_ERROR_OP_INPUT_NOT_MATCH:
            return AICL_RET_INVALID_OP_INPUT;
        case ACL_ERROR_OP_OUTPUT_NOT_MATCH:
            return AICL_RET_INVALID_OP_OUTPUT;
        case ACL_ERROR_OP_ATTR_NOT_MATCH:
            return AICL_RET_INVALID_OP_ATTR;
        case ACL_ERROR_OP_NOT_FOUND:
            return AICL_RET_OP_NOT_FOUND;
        case ACL_ERROR_OP_LOAD_FAILED:
            return AICL_RET_OP_LOAD_FAILED;
        case ACL_ERROR_UNSUPPORTED_DATA_TYPE:
            return AICL_RET_INVALID_DATA_TYPE;
        case ACL_ERROR_FORMAT_NOT_MATCH:
            return AICL_RET_INVALID_FORMAT;
        case ACL_ERROR_BIN_SELECTOR_NOT_REGISTERED:
            return AICL_RET_OP_COMPILE_FALURE;
        case ACL_ERROR_INVALID_QUEUE_ID:
            return AICL_RET_INVALID_QUEUE_ID;
        case ACL_ERROR_REPEAT_SUBSCRIBE:
            return AICL_RET_INVALID_REPEAT_SUBSCRIBE;
        case ACL_ERROR_REPEAT_FINALIZE:
            return AICL_RET_INVALID_REPEAT_FINALIZE;
        case ACL_ERROR_COMPILING_STUB_MODE:
            return AICL_RET_INVALID_COMPILING_LIB;
        case ACL_ERROR_INVALID_MAX_OPQUEUE_NUM_CONFIG:
            return AICL_RET_INVALID_OP_QUEUE_CONFIG;
        case ACL_ERROR_INVALID_OPP_PATH:
            return AICL_RET_INVALID_OP_PATH;
        case ACL_ERROR_OP_UNSUPPORTED_DYNAMIC:
            return AICL_RET_OP_STATIC_ONLY;
        case ACL_ERROR_RELATIVE_RESOURCE_NOT_CLEARED:
            return AICL_RET_RESOURCE_NOT_RELEASED;
        case ACL_ERROR_BAD_ALLOC:
            return AICL_RET_MEM_ALLOC_FAILURE;
        case ACL_ERROR_RT_INVALID_MALLOC_TYPE:
            return AICL_RET_INVALID_MEM_TYPE;
        case ACL_ERROR_MEMORY_ADDRESS_UNALIGNED:
            return AICL_RET_MEMORY_ADDR_UNALIGNED;
        case ACL_ERROR_RESOURCE_NOT_MATCH:
            return AICL_RET_RESOURCE_NOT_MATCH;
        case ACL_ERROR_INVALID_RESOURCE_HANDLE:
            return AICL_RET_INVALID_RESOURCE_HANDLE;
        case ACL_ERROR_FEATURE_UNSUPPORTED:
            return AICL_RET_FEATURE_UNSUPPORTED;
        case ACL_ERROR_UNINITIALIZE:
            return AICL_RET_NOT_INITIALIZED;
        case ACL_ERROR_RT_CONTEXT_NULL:
            return AICL_RET_INVALID_CONTEXT;
        case ACL_ERROR_RT_STREAM_MODEL:
            return AICL_RET_INVALID_STREAM;
        case ACL_ERROR_RT_MODEL_CONTEXT:
            return AICL_RET_INVALID_MODEL;
        case ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL:
            return AICL_RET_INVALID_EVENT_TIMESTAMP;
        case ACL_ERROR_RT_FILE_OPEN:
            return AICL_RET_READ_FILE_FAILURE;
        case ACL_ERROR_RT_STREAM_SUBSCRIBE:
            return AICL_RET_INVALID_STREAM_SUBSCRIBE;
        case ACL_ERROR_RT_THREAD_SUBSCRIBE:
            return AICL_RET_INVALID_THREAD_SUBSCRIBE;
        case ACL_ERROR_RT_STREAM_NO_CB_REG:
            return AICL_RET_CALLBACK_STREAM_UNREGISTERED;
        case ACL_ERROR_API_NOT_SUPPORT:
            return AICL_RET_INVALID_API;
        case ACL_ERROR_RT_INVALID_HANDLE:
            return AICL_RET_INVALID_HANDLE;
        case ACL_ERROR_RT_TASK_TIMEOUT:
            return AICL_RET_API_TIMEOUT;
        case ACL_ERROR_RT_MEMORY_FREE:
            return AICL_RET_MEMORY_FREE_FAILURE;
        case ACL_ERROR_RT_AICORE_OVER_FLOW:
            return AICL_RET_OP_OVERFLOW;
        case ACL_ERROR_INVALID_PARAM:
            return AICL_RET_INVALID_PARAM;
        case ACL_ERROR_RT_NO_PERMISSION:
            return AICL_RET_PERMISSION_DENIED;
        case ACL_ERROR_RT_NO_EVENT_RESOURCE:
            return AICL_RET_NO_EVENT_RESOURCE;
        case ACL_ERROR_RT_NO_STREAM_RESOURCE:
            return AICL_RET_NO_STREAM_RESOURCE;
        case ACL_ERROR_RT_NO_NOTIFY_RESOURCE:
            return AICL_RET_NO_NOTIFY_RESOURCE;
        case ACL_ERROR_RT_NO_MODEL_RESOURCE:
            return AICL_RET_NO_MODEL_RESOURCE;
        default:
            return AICL_RET_ERROR;
    }
}

aiclRet aiclInit(const char *configPath) {
    aclError ret = aclInit(configPath);
    return errcod_trans(ret);
}

aiclRet aiclFinalize() {
    aclError ret = aclFinalize();
    return errcod_trans(ret);
}


aiclRet aiclrtGetVersion(int32_t *majorVersion, int32_t *minorVersion, int32_t *patchVersion) {
    aclError ret = aclrtGetVersion(majorVersion, minorVersion, patchVersion);
    return errcod_trans(ret);
}

const char *aiclrtGetSocName() {
    return aclrtGetSocName();
}

aiclRet aiclrtSetDevice(int32_t deviceId) {
    aclError ret = aclrtSetDevice(deviceId);
    return errcod_trans(ret);
}

aiclRet aiclrtResetDevice(int32_t deviceId) {
    aclError ret = aclrtResetDevice(deviceId);
    return errcod_trans(ret);
}

aiclRet aiclrtGetDevice(int32_t *deviceId) {
    aclError ret = aclrtGetDevice(deviceId);
    return errcod_trans(ret);
}

aiclRet aiclrtGetRunMode(aiclrtRunMode *runMode) {
    aclError ret = aclrtGetRunMode((aclrtRunMode *)runMode);
    return errcod_trans(ret);
}

aiclRet aiclrtCreateContext(aiclrtContext *context, int32_t deviceId) {
    aclError ret = aclrtCreateContext(context, deviceId);
    return errcod_trans(ret);
}

aiclRet aiclrtDestroyContext(aiclrtContext context) {
    aclError ret = aclrtDestroyContext(context);
    return errcod_trans(ret);
}

aiclRet aiclrtSetCurrentContext(aiclrtContext context) {
    aclError ret = aclrtSetCurrentContext(context);
    return errcod_trans(ret);
}

aiclRet aiclrtGetCurrentContext(aiclrtContext *context) {
    aclError ret = aclrtGetCurrentContext(context);
    return errcod_trans(ret);
}

aiclRet aiclrtCreateStream(aiclrtStream *stream) {
    aclError ret = aclrtCreateStream(stream);
    return errcod_trans(ret);
}

aiclRet aiclrtDestroyStream(aiclrtStream stream) {
    aclError ret = aclrtDestroyStream(stream);
    return errcod_trans(ret);
}

aiclRet aiclrtGetDeviceCount(uint32_t *count) {
    aclError ret = aclrtGetDeviceCount(count);
    return errcod_trans(ret);
}

aiclRet aiclrtCreateEvent(aiclrtEvent *event) {
    aclError ret = aclrtCreateEvent(event);
    return errcod_trans(ret);
}

aiclRet aiclrtCreateEventWithFlag(aiclrtEvent *event, uint32_t flag) {
    aclError ret = aclrtCreateEventWithFlag(event, flag);
    return errcod_trans(ret);
}

aiclRet aiclrtDestroyEvent(aiclrtEvent event) {
    aclError ret = aclrtDestroyEvent(event);
    return errcod_trans(ret);
}

aiclRet aiclrtRecordEvent(aiclrtEvent event, aiclrtStream stream) {
    aclError ret = aclrtRecordEvent(event, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtResetEvent(aiclrtEvent event, aiclrtStream stream) {
    aclError ret = aclrtResetEvent(event, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtQueryEventStatus(aiclrtEvent event, aiclrtEventRecordedStatus *status) {
    aclError ret = aclrtQueryEventStatus(event, (aclrtEventRecordedStatus *)status);
    return errcod_trans(ret);
}

aiclRet aiclrtQueryEventWaitStatus(aiclrtEvent event, aiclrtEventWaitStatus *status) {
    aclError ret = aclrtQueryEventWaitStatus(event, (aclrtEventWaitStatus *)status);
    return errcod_trans(ret);
}

aiclRet aiclrtSynchronizeEvent(aiclrtEvent event) {
    aclError ret = aclrtSynchronizeEvent(event);
    return errcod_trans(ret);
}

aiclRet aiclrtEventElapsedTime(float *ms, aiclrtEvent startEvent, aiclrtEvent endEvent) {
    aclError ret = aclrtEventElapsedTime(ms, startEvent, endEvent);
    return errcod_trans(ret);
}

aiclRet aiclrtStreamWaitEvent(aiclrtStream stream, aiclrtEvent event) {
    aclError ret = aclrtStreamWaitEvent(stream, event);
    return errcod_trans(ret);
}

aiclRet aiclrtSynchronizeDevice(void) {
    aclError ret = aclrtSynchronizeDevice();
    return errcod_trans(ret);
}

aiclRet aiclrtSynchronizeStream(aiclrtStream stream) {
    aclError ret = aclrtSynchronizeStream(stream);
    return errcod_trans(ret);
}

aiclRet aiclrtSubscribeReport(uint64_t threadId, aiclrtStream stream) {
    aclError ret = aclrtSubscribeReport(threadId, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtLaunchCallback(aiclrtCallback fn, void *userData, aiclrtCallbackBlockType blockType,
                             aiclrtStream stream) {
    aclError ret = aclrtLaunchCallback(fn, userData, (aclrtCallbackBlockType)blockType, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtMalloc(void **devPtr, size_t size,
                    aiclrtMemMallocPolicy policy) {
    aclError ret = aclrtMalloc(devPtr, size, (aclrtMemMallocPolicy)policy);
    return errcod_trans(ret);
}

aiclRet aiclrtFree(void *devPtr) {
    aclError ret = aclrtFree(devPtr);
    return errcod_trans(ret);
}

aiclRet aiclrtMallocHost(void **hostPtr, size_t size) {
    aclError ret = aclrtMallocHost(hostPtr, size);
    return errcod_trans(ret);
}

aiclRet aiclrtFreeHost(void *hostPtr) {
    aclError ret = aclrtFreeHost(hostPtr);
    return errcod_trans(ret);
}

aiclRet aiclrtMemcpy(void *dst, size_t destMax, const void *src,
                     size_t count, aiclrtMemcpyKind kind) {
    aclError ret = aclrtMemcpy(dst, destMax, src, count, (aclrtMemcpyKind)kind);
    return errcod_trans(ret);
}

aiclRet aiclrtMemset(void *devPtr, size_t maxCount, int32_t value, size_t count) {
    aclError ret = aclrtMemset(devPtr, maxCount, value, count);
    return errcod_trans(ret);
}

aiclRet aiclrtMemcpyAsync(void *dst, size_t destMax, const void *src,
                         size_t count, aiclrtMemcpyKind kind, aiclrtStream stream) {
    aclError ret = aclrtMemcpyAsync(dst, destMax, src, count, (aclrtMemcpyKind)kind, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtMemsetAsync(void *devPtr, size_t maxCount, int32_t value,
                          size_t count, aiclrtStream stream) {
    aclError ret = aclrtMemsetAsync(devPtr, maxCount, value, count, stream);
    return errcod_trans(ret);
}

aiclRet aiclrtGetMemInfo(aiclrtMemAttr attr, size_t *free, size_t *total) {
    aclError ret = aclrtGetMemInfo((aclrtMemAttr)attr, free, total);
    return errcod_trans(ret);
}

size_t aiclmdlGetDatasetNumBuffers(const aiclmdlDataset *dataset) {
    return aclmdlGetDatasetNumBuffers((const aclmdlDataset *)dataset);
}

aiclDataBuffer *aiclmdlGetDatasetBuffer(const aiclmdlDataset *dataset, size_t index) {
    return (aiclDataBuffer *)aclmdlGetDatasetBuffer((const aclmdlDataset *)dataset, index);
}

aiclRet aiclmdlLoadFromFile(const char *modelPath, uint32_t *modelId) {
    aclError ret = aclmdlLoadFromFile(modelPath, modelId);
    return errcod_trans(ret);
}

aiclRet aiclmdlLoadFromMem(const void *model,  size_t modelSize, uint32_t *modelId) {
    aclError ret = aclmdlLoadFromMem(model, modelSize, modelId);
    return errcod_trans(ret);
}

aiclRet aiclmdlLoadFromFileWithMem(const char *modelPath, uint32_t *modelId, 
                                   void *workPtr, size_t workSize,
                                   void *weightPtr, size_t weightSize) {
    aclError ret = aclmdlLoadFromFileWithMem(modelPath, modelId, workPtr, 
                                             workSize, weightPtr, weightSize);
    return errcod_trans(ret);
}

aiclRet aiclmdlLoadFromMemWithMem(const void *model, size_t modelSize,
                                  uint32_t *modelId, void *workPtr, size_t workSize,
                                  void *weightPtr, size_t weightSize) {
    aclError ret = aclmdlLoadFromMemWithMem(model, modelSize, modelId, workPtr, 
                                            workSize, weightPtr, weightSize);
    return errcod_trans(ret);
}

aiclRet aiclmdlExecute(uint32_t modelId, const aiclmdlDataset *input, aiclmdlDataset *output) {
    aclError ret = aclmdlExecute(modelId, (const aclmdlDataset *)input, (aclmdlDataset *)output);
    return errcod_trans(ret);
}

aiclRet aiclmdlExecuteAsync(uint32_t modelId, const aiclmdlDataset *input,
                            aiclmdlDataset *output, aiclrtStream stream) {
    aclError ret = aclmdlExecuteAsync(modelId, (const aclmdlDataset *)input, (aclmdlDataset *)output, stream);
    return errcod_trans(ret);
}

aiclRet aiclmdlUnload(uint32_t modelId) {
    aclError ret = aclmdlUnload(modelId);
    return errcod_trans(ret);
}

aiclRet aiclmdlQuerySize(const char *fileName, size_t *workSize, size_t *weightSize) {
    aclError ret = aclmdlQuerySize(fileName, workSize, weightSize);
    return errcod_trans(ret);
}

aiclRet aiclmdlQuerySizeFromMem(const void *model, size_t modelSize, size_t *workSize,
                                 size_t *weightSize) {
    aclError ret = aclmdlQuerySizeFromMem(model, modelSize, workSize, weightSize);
    return errcod_trans(ret);
}

aiclmdlConfigHandle *aiclmdlCreateConfigHandle() {
    return (aiclmdlConfigHandle *)aclmdlCreateConfigHandle();
}

aiclRet aiclmdlDestroyConfigHandle(aiclmdlConfigHandle *handle) {
    aclError ret = aiclmdlDestroyConfigHandle(handle);
    return errcod_trans(ret);
}

aiclRet aiclmdlSetConfigOpt(aiclmdlConfigHandle *handle, aiclmdlConfigAttr attr,
                            const void *attrValue, size_t valueSize) {
    aclError ret = aclmdlSetConfigOpt((aclmdlConfigHandle *)handle, (aclmdlConfigAttr)attr, attrValue, valueSize);
    return errcod_trans(ret);
}

aiclRet aiclmdlLoadWithConfig(const aiclmdlConfigHandle *handle, uint32_t *modelId) {
    aclError ret = aclmdlLoadWithConfig((aclmdlConfigHandle *)handle, modelId);
    return errcod_trans(ret);
}

aiclRet aiclopCompile(const char *opType, int numInputs,
                      const aiclTensorDesc *const inputDesc[],
                      int numOutputs,
                      const aiclTensorDesc *const outputDesc[],
                      const aiclopAttr *attr,
                      aiclopEngineType engineType,
                      aiclopCompileType compileFlag, const char *opPath) {
    aclError ret = aclopCompile(opType, numInputs, (const aclTensorDesc *const *)inputDesc, numOutputs, 
                                (const aclTensorDesc *const *)outputDesc, (aclopAttr *)attr,
                                (aclopEngineType)engineType, (aclopCompileType)compileFlag, opPath);
    return errcod_trans(ret);
}

aiclRet aiclopSetCompileFlag(aiclOpCompileFlag flag) {
    aclError ret = aclopSetCompileFlag((aclOpCompileFlag)flag);
    return errcod_trans(ret);
}

aiclRet aiclopSetModelDir(const char *modelDir) {
    aclError ret = aclopSetModelDir(modelDir);
    return errcod_trans(ret);
}

aiclRet aiclopLoad(const void *model, size_t modelSize) {
    aclError ret = aclopLoad(model, modelSize);
    return errcod_trans(ret);
}

aiclRet aiclopCompileAndExecute(const char *opType,
    int numInputs, aiclTensorDesc *inputDesc[], aiclDataBuffer *inputs[],
    int numOutputs, aiclTensorDesc *outputDesc[], aiclDataBuffer *outputs[],
    aiclopAttr *attr, aiclopEngineType engineType, aiclopCompileType compileFlag,
    const char *opPath, aiclrtStream stream) {
    aclError ret = aclopCompileAndExecuteV2(opType, numInputs, (aclTensorDesc **)inputDesc, (aclDataBuffer **)inputs,
                                             numOutputs, (aclTensorDesc **)outputDesc, (aclDataBuffer **)outputs,
                                             (aclopAttr *)attr, (aclopEngineType)engineType, (aclopCompileType)compileFlag, opPath, stream);
    return errcod_trans(ret);
}

aiclRet aiclopCreateHandle(const char *opType, int numInputs,
                            const aiclTensorDesc *const inputDesc[],
                            int numOutputs,
                            const aiclTensorDesc *const outputDesc[],
                            const aiclopAttr *opAttr, aiclopHandle **handle) {
    aclError ret = aiclopCreateHandle(opType, numInputs, inputDesc, numOutputs,
                                       outputDesc, opAttr, handle);
    return errcod_trans(ret);
}

void aiclopDestroyHandle(aiclopHandle *handle) {
     aclopDestroyHandle((aclopHandle *)handle);
}

aiclRet aiclopExecWithHandle(aiclopHandle *handle, int numInputs,
                             const aiclDataBuffer *const inputs[], int numOutputs,
                             aiclDataBuffer *const outputs[], aiclrtStream stream) {
    aclError ret = aclopExecWithHandle((aclopHandle *)handle, numInputs, (aclDataBuffer **)inputs, numOutputs,
                                       (aclDataBuffer **)outputs, stream);
    return errcod_trans(ret);
}

aiclRet aiclopInferShape(const char *opType, int numInputs,
                        aiclTensorDesc *inputDesc[], aiclDataBuffer *inputs[],
                        int numOutputs,  aiclTensorDesc *outputDesc[], aiclopAttr *attr) {
    aclError ret = aclopInferShape(opType, numInputs, (aclTensorDesc **)inputDesc, (aclDataBuffer **)inputs,
                                   numOutputs, (aclTensorDesc **)outputDesc, (aclopAttr *)attr);
    return errcod_trans(ret);
}

aiclTensorDesc *aiclCreateTensorDesc(aiclDataType dataType, int numDims,
                                     const int64_t *dims,  aiclFormat format) {
    return (aiclTensorDesc *)aclCreateTensorDesc((aclDataType)dataType, numDims, dims, (aclFormat)format);
}

void aiclDestroyTensorDesc(const aiclTensorDesc *desc) {
    aclDestroyTensorDesc((aclTensorDesc *)desc);
}

aiclRet aiclSetTensorFormat(aiclTensorDesc *desc, aiclFormat format) {
    aclError ret = aclSetTensorFormat((aclTensorDesc *)desc, (aclFormat)format);
    return errcod_trans(ret);
}

aiclRet aiclSetTensorPlaceMent(aiclTensorDesc *desc, aiclMemType memType) {
    aclError ret = aclSetTensorPlaceMent((aclTensorDesc *)desc, (aclMemType)memType);
    return errcod_trans(ret);
}

aiclRet aiclSetTensorShape(aiclTensorDesc *desc, int numDims, const int64_t *dims) {
    aclError ret = aclSetTensorShape((aclTensorDesc *)desc, numDims, dims);
    return errcod_trans(ret);
}

aiclRet aiclSetTensorShapeRange(aiclTensorDesc* desc, size_t dimsCount,
                                int64_t dimsRange[][AICL_TENSOR_SHAPE_RANGE_NUM]) { 
    aclError ret = aclSetTensorShape((aclTensorDesc *)desc, dimsCount, (int64_t *)dimsRange);
    return errcod_trans(ret);
}

void aiclSetTensorDescName(aiclTensorDesc *desc, const char *name) {
    aclSetTensorDescName((aclTensorDesc *)desc, name);
}

aiclRet aiclSetTensorConst(aiclTensorDesc *desc, void *dataBuffer, size_t length) {
    aclError ret = aclSetTensorConst((aclTensorDesc *)desc, dataBuffer, length);
    return errcod_trans(ret);
}

aiclDataType aiclGetTensorDescType(const aiclTensorDesc *desc) {
    return (aiclDataType)aclGetTensorDescType((const aclTensorDesc *)desc);
}

aiclFormat aiclGetTensorDescFormat(const aiclTensorDesc *desc) {
    return (aiclFormat)aclGetTensorDescFormat((const aclTensorDesc *)desc);
}

size_t aiclGetTensorDescSize(const aiclTensorDesc *desc) {
    return aclGetTensorDescSize((const aclTensorDesc *)desc);
}

size_t aiclGetTensorDescElementCount(const aiclTensorDesc *desc) {
    return aclGetTensorDescElementCount((const aclTensorDesc *)desc);
}

size_t aiclGetTensorDescNumDims(const aiclTensorDesc *desc) {
    return aclGetTensorDescNumDims((const aclTensorDesc *)desc);
}

aiclDataBuffer *aiclCreateDataBuffer(void *data, size_t size) {
    return (aiclDataBuffer *)aclCreateDataBuffer(data, size);
}

aiclRet aiclDestroyDataBuffer(const aiclDataBuffer *dataBuffer) {
    aclError ret = aclDestroyDataBuffer((aclDataBuffer *)dataBuffer);
    return errcod_trans(ret);
}

aiclopAttr *aiclopCreateAttr() {
    return (aiclopAttr *)aclopCreateAttr();
}

aiclRet aiclopSetAttrBool(aiclopAttr *attr, const char *attrName, uint8_t attrValue) {
    aclError ret = aclopSetAttrBool((aclopAttr *)attr, attrName, attrValue);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrInt(aiclopAttr *attr, const char *attrName, int64_t attrValue) {
    aclError ret = aclopSetAttrInt((aclopAttr *)attr, attrName, attrValue);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrFloat(aiclopAttr *attr, const char *attrName, float attrValue) {
    aclError ret = aclopSetAttrFloat((aclopAttr *)attr, attrName, attrValue);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrString(aiclopAttr *attr, const char *attrName, const char *attrValue) {
    aclError ret = aclopSetAttrString((aclopAttr *)attr, attrName, attrValue);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrDataType(aiclopAttr *attr, const char *attrName, aiclDataType attrValue) {
    aclError ret = aclopSetAttrDataType((aclopAttr *)attr, attrName, (aclDataType)attrValue);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListDataType(aiclopAttr *attr, const char *attrName, int numValues,
                                  const aiclDataType values[]) {
    aclError ret = aclopSetAttrListDataType((aclopAttr *)attr, attrName, numValues, (const aclDataType *)values);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListBool(aiclopAttr *attr, const char *attrName, int numValues,
                              const uint8_t *values) {
    aclError ret = aclopSetAttrListBool((aclopAttr *)attr, attrName, numValues, values);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListInt(aiclopAttr *attr, const char *attrName, int numValues,
                             const int64_t *values) {
    aclError ret = aclopSetAttrListInt((aclopAttr *)attr, attrName, numValues, values);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListFloat(aiclopAttr *attr, const char *attrName, int numValues,
                               const float *values) {
    aclError ret = aclopSetAttrListFloat((aclopAttr *)attr, attrName, numValues, values);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListString(aiclopAttr *attr, const char *attrName, int numValues,
                                const char **values) {
    aclError ret = aclopSetAttrListString((aclopAttr *)attr, attrName, numValues, values);
    return errcod_trans(ret);
}

aiclRet aiclopSetAttrListListInt(aiclopAttr *attr, const char *attrName,
                                 int numLists, const int *numValues,
                                 const int64_t *const values[]) {
    aclError ret = aclopSetAttrListListInt((aclopAttr *)attr, attrName, numLists, numValues, values);
    return errcod_trans(ret);
}

aiclmdlDataset *aiclmdlCreateDataset() {
    return (aiclmdlDataset *)aclmdlCreateDataset();
}

aiclRet aiclmdlDestroyDataset(const aiclmdlDataset *dataset) {
    aclError ret = aclmdlDestroyDataset((const aclmdlDataset *)dataset);
    return errcod_trans(ret);
}

aiclRet aiclopExecute(const char *opType,int numInputs,
                        aiclTensorDesc *inputDesc[],
                        aiclDataBuffer *inputs[],
                        int numOutputs,
                        aiclTensorDesc *outputDesc[],
                        aiclDataBuffer *outputs[],
                        aiclopAttr *attr,
                        aiclrtStream stream) {
    aclError ret = aclopExecuteV2(opType, numInputs, (aclTensorDesc **)inputDesc,
                                        (aclDataBuffer **)inputs, numOutputs, 
                                        (aclTensorDesc **)outputDesc, (aclDataBuffer **)outputs,
                                        (aclopAttr *)attr, stream);
    return errcod_trans(ret);
}

aiclRet aiclmdlAddDatasetBuffer(aiclmdlDataset *dataset, aiclDataBuffer *dataBuffer) {
    aclError ret = aclmdlAddDatasetBuffer((aclmdlDataset *)dataset, (aclDataBuffer *)dataBuffer);
    return errcod_trans(ret);
}

aiclmdlDesc *aiclmdlCreateDesc() {
    return (aiclmdlDesc *)aclmdlCreateDesc();
}

aiclRet aiclmdlDestroyDesc(aiclmdlDesc *modelDesc) {
    aclError ret = aclmdlDestroyDesc((aclmdlDesc *)modelDesc);
    return errcod_trans(ret);
}

aiclRet aiclmdlGetDesc(aiclmdlDesc *modelDesc, uint32_t modelId) {
    aclError ret = aclmdlGetDesc((aclmdlDesc *)modelDesc, modelId);
    return errcod_trans(ret);
}

size_t aiclmdlGetNumInputs(aiclmdlDesc *modelDesc) {
    return aclmdlGetNumInputs((aclmdlDesc *)modelDesc);
}

size_t aiclmdlGetNumOutputs(aiclmdlDesc *modelDesc) {
    return aclmdlGetNumOutputs((aclmdlDesc *)modelDesc);
}

size_t aiclmdlGetInputSizeByIndex(aiclmdlDesc *modelDesc, size_t index) {
    return aclmdlGetInputSizeByIndex((aclmdlDesc *)modelDesc, index);
}

size_t aiclmdlGetOutputSizeByIndex(aiclmdlDesc *modelDesc, size_t index) {
    return aclmdlGetOutputSizeByIndex((aclmdlDesc *)modelDesc, index);
}

void aiclopDestroyAttr(const aiclopAttr *attr) {
    aclopDestroyAttr((aclopAttr *)attr);
}

aiclRet aiclGetTensorDescDim(const aclTensorDesc *desc, size_t index, int64_t *dimSize) {
    aclError ret = aclGetTensorDescDimV2(desc, index, dimSize);
    return errcod_trans(ret);
}

aiclRet aiclmdlCreateAndGetOpDesc(uint32_t deviceId, uint32_t streamId,
    uint32_t taskId, char *opName, size_t opNameLen, aiclTensorDesc **inputDesc, size_t *numInputs,
    aiclTensorDesc **outputDesc, size_t *numOutputs) {
    aclError ret = aclmdlCreateAndGetOpDesc(deviceId, streamId, taskId, opName, opNameLen,
                                            (aclTensorDesc **)inputDesc, numInputs, (aclTensorDesc **)outputDesc, numOutputs);
    return errcod_trans(ret);
}

void *aiclGetDataBufferAddr(const aiclDataBuffer *dataBuffer) {
    aclGetDataBufferAddr((aclDataBuffer *)dataBuffer);
}

size_t aiclGetDataBufferSize(const aiclDataBuffer *dataBuffer) {
    return aclGetDataBufferSizeV2((aclDataBuffer *)dataBuffer);
}

aiclTensorDesc *aiclGetTensorDescByIndex(aiclTensorDesc *desc, size_t index) {
    return (aiclTensorDesc *)aclGetTensorDescByIndex((aclTensorDesc *)desc, index);
}

aiclRet aiclrtSetOpWaitTimeout(uint32_t timeout) {
    aclError ret = aclrtSetOpWaitTimeout(timeout);
    return errcod_trans(ret);
}

aiclRet aiclmdlGetInputDims(const aiclmdlDesc *modelDesc, size_t index, aiclmdlIODims *dims) {
    aclError ret = aclmdlGetInputDims((const aclmdlDesc *)modelDesc, index, (aclmdlIODims *)dims);
    return errcod_trans(ret);
}

aiclRet aiclmdlGetOutputDims(const aiclmdlDesc *modelDesc, size_t index, aiclmdlIODims *dims) {
    aclError ret = aclmdlGetOutputDims((const aclmdlDesc *)modelDesc, index, (aclmdlIODims *)dims);
    return errcod_trans(ret);
}

const char *aiclmdlGetInputNameByIndex(const aiclmdlDesc *modelDesc, size_t index) {
    return aclmdlGetInputNameByIndex((const aclmdlDesc *)modelDesc, index);
}

const char *aiclmdlGetOutputNameByIndex(const aiclmdlDesc *modelDesc, size_t index) {
    return aclmdlGetOutputNameByIndex((const aclmdlDesc *)modelDesc, index);
}

aiclFormat aiclmdlGetInputFormat(const aiclmdlDesc *modelDesc, size_t index) {
    return (aiclFormat)aclmdlGetInputFormat((const aclmdlDesc *)modelDesc, index);
}

aiclFormat aiclmdlGetOutputFormat(const aiclmdlDesc *modelDesc, size_t index) {
    return (aiclFormat)aclmdlGetOutputFormat((const aclmdlDesc *)modelDesc, index);
}

aiclDataType aiclmdlGetInputDataType(const aiclmdlDesc *modelDesc, size_t index) {
    return (aiclDataType)aclmdlGetInputDataType((const aclmdlDesc *)modelDesc, index);
}

aiclDataType aiclmdlGetOutputDataType(const aiclmdlDesc *modelDesc, size_t index) {
    return (aiclDataType)aclmdlGetOutputDataType((const aclmdlDesc *)modelDesc, index);
}

aiclRet aiclGetTensorDescDimRange(const aiclTensorDesc *desc, size_t index,
                                  size_t dimRangeNum, int64_t *dimRange) {
    aclError ret = aclGetTensorDescDimRange((const aclTensorDesc *)desc, index, dimRangeNum, dimRange);
    return errcod_trans(ret);
}

aiclRet aiclrtProcessReport(int32_t timeout) {
    aclError ret = aclrtProcessReport(timeout);
    return errcod_trans(ret);
}

aiclRet aiclrtUnSubscribeReport(uint64_t threadId, aiclrtStream stream) {
    aclError ret = aclrtUnSubscribeReport(threadId, stream);
    return errcod_trans(ret);
}

const char *aiclGetTensorDescName(aiclTensorDesc *desc) {
    return aclGetTensorDescName((aclTensorDesc *)desc);
}

aiclRet aiclrtSynchronizeStreamWithTimeout(aiclrtStream stream, int32_t timeout) {
    aclError ret = aclrtSynchronizeStreamWithTimeout(stream, timeout);
    return errcod_trans(ret);
}